package cn.itcast.nems.studentrecord.web.controller.b;

import cn.itcast.ic.common.bean.Page;
import cn.itcast.nems.journal.dto.JournalChangeDateDTO;
import cn.itcast.nems.journal.dto.JournalChangeDateLineDTO;
import cn.itcast.nems.journal.dto.JournalChangeDateSearch;
import cn.itcast.nems.journal.service.JournalChangeDateLineService;
import cn.itcast.nems.journal.service.JournalChangeDateService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 改期凭单
 *
 * @author liyong
 * @since 2024/01/12 3:47 PM
 **/
@RestController
@RequestMapping("/b/journal/change/date")
@RequiredArgsConstructor
@Slf4j
public class JournalChangeDateController {
    private final JournalChangeDateService journalChangeDateService;
    private final JournalChangeDateLineService journalChangeDateLineService;

    @PostMapping("/search")
    public ResponseEntity<Page<JournalChangeDateDTO>> search(@RequestBody JournalChangeDateSearch search) {
        final Page<JournalChangeDateDTO> result = this.journalChangeDateService.search(search);
        return ResponseEntity.ok().body(result);
    }

    @GetMapping("/detail/{journalId}")
    public ResponseEntity<Map<String, Object>> detail(@PathVariable("journalId") String journalId) {
        final JournalChangeDateDTO journal = this.journalChangeDateService.getJournal(journalId);
        final List<JournalChangeDateLineDTO> journalLines = this.journalChangeDateLineService.findJournalLines(journalId);
        Map<String, Object> result = new HashMap<>(2);
        result.put("journal", journal);
        result.put("journalLines", journalLines);
        return ResponseEntity.ok().body(result);
    }

}
